import numpy as np  
import matplotlib.pyplot as plt  

def Bspline(n, t, i, x): # spline function
  if (n == 0):
    return (x > t[i - 1]) * (x <= i) * 1.0
  else:
    return (x - t[i - 1]) / n * Bspline(n - 1, t, i, x) + (t[i] + n - x) / n * Bspline(n - 1, t ,i + 1, x)
n = 2 # degree of splines
m = 6 # number of splines (range of i)
t = np.zeros(100) # knots
for i in range(0, 90): # set knots
  t[i]=i
x = np.linspace(0, m+3, 1000)
Z = np.linspace(0, m+3, m+4) 
plt.plot(Z, np.zeros(len(Z)), 'o')
for i in range(2, 1+m):
  plt.plot(x, Bspline(n, t, i, x), label=f'$B_{i}^{n}$')
plt.legend()
plt.savefig("V.png")